var urlParam = window.location.search;
var param = urlParam.substring(urlParam.indexOf('list=') + 5,urlParam.length);
var hls;
var video;
var listParam ;
var isFullScreen = false;
try{
    listParam = JSON.parse(decodeURI(param))
}catch (e){
    console.error("url参数错误");
}

var vueApp = new Vue({
    el:'#app',
    data:{
        headLine:'摄像头名称',
        listParam:listParam,
        centerBottom:'',
        cameraListDisplay:'',
        isPosition: false
    },
    methods:{
        removerCameraList(){
            if(this.isPosition){
                this.isPosition = true;
                this.cameraListDisplay = 'none';
            }else{
                this.cameraListDisplay = '';
            }
        },
        changeUrl(url){
            console.log("fjidfjei")
            console.log(url);

            hls.destroy();
            playHls(url);
        }
    }
})

//list=[{"name":"CCTV1","url":"http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8"},{"name":"CCTV3","url":"http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8"},{"name":"CCTV5","url":"http://ivi.bupt.edu.cn/hls/cctv5phd.m3u8"}]




playHls(listParam[0].url);

function playHls(url){
    video = document.getElementById('video');
    if (Hls.isSupported()) {
        //hls.loadSource(videoSrc);
        hls = new Hls();
        console.log(hls);
        hls.attachMedia(video);

        hls.on(Hls.Events.MEDIA_ATTACHED, function () {
            console.log('video and hls.js are now bound together !');
            hls.loadSource(url);
            hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
                console.log(
                    'manifest loaded, found ' + data.levels.length + ' quality level'
                );
            });
        });
    } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
        video.src = url;
    }

}


function fullScreen() {
    //var ele = document.documentElement;
    var ele = document.getElementById("video");
    if (ele.requestFullscreen) {
        ele.requestFullscreen();
    } else if (ele.mozRequestFullScreen) {
        ele.mozRequestFullScreen();
    } else if (ele.webkitRequestFullScreen) {
        ele.webkitRequestFullScreen();
    }
}